<?php

/**
 * @author christian
 * @copyright 2011
 */

//echo "registrar ....";
//echo getcwd();
//echo basename(getcwd());



$ruta=$_SERVER['DOCUMENT_ROOT']."/viventura"."/MDTour";
include_once("$ruta/conf/CConfig.php");
include_once("$ruta/elements/head.tpl");
include_once("$ruta/MDTourGeneral/CTourTableDraw.php");
include_once("$ruta/star.php");
include_once("$ruta/view/CDrawMenuTour.php");
include_once("$ruta/MDTourGeneral/CTourEditDraw.php");
include_once("$ruta/MDTourGeneral/CDrawPageReg.php");


if (!isset($_GET['default'])) {$_GET['default'] = "2"; }
$default=$_GET['default'];

if (!isset($_GET['idOpe'])) {$_GET['idOpe'] = "NULL"; }
$idOpe=$_GET['idOpe'];

if (!isset($_GET['tourcreate'])) {$_GET['tourcreate'] = "NULL"; }
$tourcreate=$_GET['tourcreate'];


if (!isset($_POST['idPack'])) {$_POST['idPack'] = "NULL"; }
$idPack=$_POST['idPack'];

//if($idPack=="NULL"){
//    if (!isset($_GET['codigo'])) {$_GET['codigo'] = "NULL"; }
//    $idPack=$_GET['codigo'];    
//}

if (!isset($_POST['idTour'])) {$_POST['idTour'] = "NULL"; }
$idTour=$_POST['idTour'];

//if (!isset($_POST['type'])) {$_POST['type'] = "NULL"; $id=$_GET['codigo'];}
//if (!isset($_GET['codigo'])) {$_GET['codigo'] = "NULL"; $id=$_POST['type'];}




// Recibe parametro de SmallDefinePack


if($default==1){$action_title= "Editando tour"; $action="edittour=1";}
if($default==0){$action_title= "Editando paquete"; $action="editpack=1";}
if($tourcreate==1){$action_title= "Nuevo Tour"; $action="tourcreate=1";}


$items=array("Nuevo Tour"=>"CSmallDefinePack.php","Nuevo paquete"=>"CTourEdit.php?codigo=159&default=2","Ver paquetes"=>"/viventura/MDTour/","Otra"=>"g");

CDrawMenuTour::getInstance()->setMenu($items);


CDrawMenuTour::getInstance()->DrawDivAdBegin("content_area_user_title","1");echo "<h1>$action_title</h1>";




CDrawMenuTour::getInstance()->rigth_side_begin();

$maintable="pack_has_tour";
$mainfield="idPackTour";
//$table1="tour";
$subfield="TOUR_idTour";



$action="CRegistroTour.php?$action";$name="formulario_registro";$method="post";$NAME="";
CTourEditDraw::getInstance()->DrawHead($action,$name,$method,$NAME);

////////hidden//////////
CTourEditDraw::getInstance()->HiddenValue($default,"default");
CTourEditDraw::getInstance()->HiddenValue($idPack,"idPack");


/**
 * EDICION DE TOUR===============================================================================================
 * 
 */ if($default==1){
    
    if (!isset($_GET['codigo'])) {$_GET['codigo'] = "NULL"; }
    $idPackTour=$_GET['codigo'];
    
    CTourEditDraw::getInstance()->HiddenValue($idPackTour,"idPackTour");
     
    $NomPack="";    
    $query = "select NomPack, idPack from pack where idPack = (select pack_idPack from pack_has_tour where idPackTour=$idPackTour)";
 
     $result = CModelo::getInstance()->getData($query);
 
    
     foreach($result as $i=>$v)
     {
        $table = $v;
            foreach ($table as $r => $c){
                $NomPack[] = $c; 
            }
     }

     $paquete = $NomPack[0]. " (". $NomPack[1].") ";
     
     CDrawPageReg::getInstance()->DrawReadOnly("idPackHead","Paquete base",$paquete);


    ////////////////////////////////Datos generales del tour//////////////////////////////////
    CTourEditDraw::getInstance()->DrawSection("Datos generales");
    $items = array("NamTour"=>"Nombre del tour");
    $val_items = array (":required");
    CTourEditDraw::getInstance()->DrawTextFillBox("",$items, "pack_has_tour", "idPackTour", $idPackTour,$val_items);
  
  
     CTourEditDraw::getInstance()->DrawSection("Información general del nuevo tour");
      echo "<div id='dashboard_info'>";
              
 //    $items = array("NomPack"=>"Nombre del tour");
 //    $val_items = (":required");
 //    CTourEditDraw::getInstance()->DrawTextFillBox("",$items, "Pack", "idPack", $idPack,$val_items);
     
//     CTourEditDraw::getInstance()->HiddenValue($idTour,"idTour");
     
     echo "<rigth><h2>Duración del tour</h2><rigth>";
     
      $query = "select DateBegTour, DateEndTour from pack_has_tour where idPackTour=$idPackTour";
     //echo $query;
     $answer = CModelo::getInstance()->getData($query);

    foreach($answer as $a=>$b)
    {
        $table = $b;
        foreach ($table as $a1 => $b1){
        $range[] =  CDrawPageReg::getInstance()->aphp($b1); 
        }
    }
     
     
     $date=array("Fecha de inicio","Fecha de terminación");
     CDrawPageReg::getInstance()->DateFromToFill("Duración del tour",$date,$range[0],$range[1]); //date (0/1) esta en parametros
             
             
     echo "</div></br>";
     
     echo "<rigth><h2>Datos del Tour Conductor</h2><rigth>";
     $campos = array("idGuide"=>"idGuide", "FirstNamGui"=>"FirstNamGui", " LastNamGui"=> "LastNamGui");
     
//     $maintable, $table,$campos,$NAME, $id, $idnomain, $size)
     echo "<div id='dashboard_info'>";     
     CTourEditDraw::getInstance()->DrawSelect("pack_has_tour_has_guidetc","guidetc",$campos,"Guía 1",$idPackTour,"guidetc_idGuide",1,1);
     CTourEditDraw::getInstance()->DrawSelect("pack_has_tour_has_guidetc","guidetc",$campos,"Guía 2",$idPackTour,"guidetc_idGuide",1,2);     
     echo "</div>";
     //CTourEditDraw::getInstance()->DrawSelect("guidetc", $campos, "Tour Conductor 2", "idGuide2");
    
    $campos=array('IdExt','NomExt');
    CTourEditDraw::getInstance()->DrawMultipleSelect("pack_has_tour_has_extensiones","extensiones",$campos,"Extensiones",$idPack,"extensiones_idExt");

   
    CTourEditDraw::getInstance()->DrawSubmmit("Actualizar tour");
}
  
 /**
 * FIN DE EDICION DE TOUR===============================================================================================
 * 
 */  
  
  
  ////////////////////////////////////////////////////////////////////////////////////////////
 /**
 * EDICION DE PAQUETE ===============================================================================================
 * 
 */ 
 if($default==0) {
   
    if (!isset($_GET['codigo'])) {$_GET['codigo'] = "NULL"; }
    $idPackTour=$_GET['codigo'];
    
    $idPack = CTourEditDraw::getInstance()->getDefaultTour("pack_has_tour","PACK_idPack",$idPackTour,"PACK_idPack");

    CTourEditDraw::getInstance()->HiddenValue($idPack,"idPack");
      
    $items = array("NomPack"=>"Nombre del tour","CostPerOne"=>"Costo por una persona","CostPerTwo"=>"Costo por dos personas");
    $val= array(":required",":integer",":integer");
    CTourEditDraw::getInstance()->DrawTextFillBox("",$items,"pack","idPack",$idPack,$val);
   
   
    $field=array("idPack","IntComPack");
    CTourEditDraw::getInstance()->DrawAreaFill("Descripción del paquete","pack",$field,$idPack);
        
    $campos=array('IdExt','NomExt');
    CTourEditDraw::getInstance()->DrawMultipleSelect("pack_has_tour_has_extensiones","extensiones",$campos,"Extensiones",$idPackTour,"extensiones_idExt");
    
    $hoteles = CConfig::getInstance()->rutalogica."/MDHoteles/index.php?codigo=$idPackTour";
        
        
    CTourEditDraw::getInstance()->DrawButton("Ver hoteles asignados",$hoteles);

    CTourEditDraw::getInstance()->DrawSubmmit("Actualizar paquete");
    
        
}

/**
 * FIN DE EDICION DE PAQUETE ===============================================================================================
 * 
 */ 

////////Default tour para editar el paquete, default tour como plantilla para el nuevo paquete////////////
//$idPackTour = CTourEditDraw::getInstance()->getDefaultTour("pack_has_tour","PACK_idPack",$idPack,"idPackTour"); //para el defaultour
//CTourEditDraw::getInstance()->HiddenValue($idPackTour, "idPackTour");

//$idOfi = CTourEditDraw::getInstance()->getAnyId("pack","idPack",$idPack,"OFICINAS_idOfi");
//$idOpe = CTourEditDraw::getInstance()->getAnyId("oficinas","idOfi",$idOfi,"OPERADOR_idOpe");
//CTourEditDraw::getInstance()->HiddenValue($idOpe,"idOpe");




/**
 * CREACION DE TOUR===============================================================================================
 * 
 */ 
if($tourcreate == 1){
    
     if (!isset($_GET['codigo'])) {$_GET['codigo'] = "NULL"; }
    $idPack=$_GET['codigo'];
    CTourEditDraw::getInstance()->HiddenValue($idPack,"idPack");
    
    $idTour = CTourEditDraw::getInstance()->getDefaultTour("pack_has_tour","PACK_idPack",$idPack,"tour_idTour");
    CTourEditDraw::getInstance()->HiddenValue($idTour,"idTour");
        
    $idPackTour = CTourEditDraw::getInstance()->getDefaultTour("pack_has_tour","PACK_idPack",$idPack,"idPackTour");
    CTourEditDraw::getInstance()->HiddenValue($idPackTour,"idPackTour");
   
    
     
    $NomPack="";    
    $query = "select NomPack, idPack from pack where idPack = $idPack";
 
     $result = CModelo::getInstance()->getData($query);
 
    
     foreach($result as $i=>$v)
     {
        $table = $v;
            foreach ($table as $r => $c){
                $NomPack[] = $c; 
            }
     }

     $paquete = $NomPack[0]. " (". $NomPack[1].") ";
     
     
     CDrawPageReg::getInstance()->DrawReadOnly("idPackHead","Paquete base",$paquete);

     $packname = array("NomPack"=>"Nombre del tour (personalizar)");
     $val_packname = array (":required");
     CTourEditDraw::getInstance()->DrawTextFillBox("",$packname, "pack", "idPack", $idPack,$val_packname);
  

     CTourEditDraw::getInstance()->DrawSection("Información general del nuevo tour");
      echo "<div id='dashboard_info'>";
              
   
     echo "<rigth><h2>Duración del tour</h2><rigth>";
     
     
     $date=array("Fecha de inicio","Fecha de terminación");
     CDrawPageReg::getInstance()->DateFromTo("Duración del tour",$date); //date (0/1) esta en parametros
             
             
     echo "</div></br>";
     
     echo "<rigth><h2>Datos del Tour Conductor</h2><rigth>";
     
     
     $campos = array("idGuide"=>"idGuide", "FirstNamGui"=>"FirstNamGui", " LastNamGui"=> "LastNamGui");
     echo "<div id='dashboard_info'>";     
     CTourEditDraw::getInstance()->DrawSelect("pack_has_tour_has_guidetc","guidetc",$campos,"Guía 1",$idPackTour,"guidetc_idGuide",1,1);
     CTourEditDraw::getInstance()->DrawSelect("pack_has_tour_has_guidetc","guidetc",$campos,"Guía 2",$idPackTour,"guidetc_idGuide",1,2);     
     echo "</div>";
    
    $campos=array('IdExt','NomExt');
    CTourEditDraw::getInstance()->DrawMultipleSelect("pack_has_tour_has_extensiones","extensiones",$campos,"Extensiones",$idPack,"extensiones_idExt");
    
    CDrawPageReg::getInstance()->DrawSubmmit("Crear tour");

}

/**
 * FIN DE CREACION DE TOUR===============================================================================================
 * 
 */ 
CDrawPageReg::getInstance()->DrawFoot();
CDrawMenuTour::getInstance()->rigth_side_end();

CDrawPageReg::getInstance()->DrawButton("Ver default tours","MDTourGeneral/index.php?default=1");
   
CDrawMenuTour::getInstance()->DrawDivAdEnd();


?>